
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.Sale;
import cn.edu.scau.cmi.hombio.domain.SalePig;
import cn.edu.scau.cmi.hombio.domain.Task;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class SaleServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected SaleService service;

	/**
	 * Instantiates a new SaleServiceTest.
	 *
	 */
	public SaleServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Load an existing Sale entity
	* 
	 */
	@Test
	public void loadSales() {
		Set<Sale> response = null;
		response = service.loadSales();
		// TODO: JUnit - Add assertions to test outputs of operation: loadSales
	}

	/**
	 * Operation Unit Test
	* Delete an existing Sale entity
	* 
	 */
	@Test
	public void deleteSale() {
		// TODO: JUnit - Populate test inputs for operation: deleteSale 
		Sale sale = new cn.edu.scau.cmi.hombio.domain.Sale();
		service.deleteSale(sale);
	}

	/**
	 * Operation Unit Test
	* Delete an existing Employee entity
	* 
	 */
	@Test
	public void deleteSaleEmployee() {
		// TODO: JUnit - Populate test inputs for operation: deleteSaleEmployee 
		Integer sale_id = 0;
		Integer related_employee_id = 0;
		Sale response = null;
		response = service.deleteSaleEmployee(sale_id, related_employee_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteSaleEmployee
	}

	/**
	 * Operation Unit Test
	* Save an existing Employee entity
	* 
	 */
	@Test
	public void saveSaleEmployee() {
		// TODO: JUnit - Populate test inputs for operation: saveSaleEmployee 
		Integer id = 0;
		Employee related_employee = new cn.edu.scau.cmi.hombio.domain.Employee();
		Sale response = null;
		response = service.saveSaleEmployee(id, related_employee);
		// TODO: JUnit - Add assertions to test outputs of operation: saveSaleEmployee
	}

	/**
	 * Operation Unit Test
	* Return a count of all Sale entity
	* 
	 */
	@Test
	public void countSales() {
		Integer response = null;
		response = service.countSales();
		// TODO: JUnit - Add assertions to test outputs of operation: countSales
	}

	/**
	 * Operation Unit Test
	* Return all Sale entity
	* 
	 */
	@Test
	public void findAllSales() {
		// TODO: JUnit - Populate test inputs for operation: findAllSales 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Sale> response = null;
		response = service.findAllSales(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllSales
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void saveSaleTask() {
		// TODO: JUnit - Populate test inputs for operation: saveSaleTask 
		Integer id_1 = 0;
		Task related_task = new cn.edu.scau.cmi.hombio.domain.Task();
		Sale response = null;
		response = service.saveSaleTask(id_1, related_task);
		// TODO: JUnit - Add assertions to test outputs of operation: saveSaleTask
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findSaleByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findSaleByPrimaryKey 
		Integer id_2 = 0;
		Sale response = null;
		response = service.findSaleByPrimaryKey(id_2);
		// TODO: JUnit - Add assertions to test outputs of operation: findSaleByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deleteSaleTask() {
		// TODO: JUnit - Populate test inputs for operation: deleteSaleTask 
		Integer sale_id_1 = 0;
		Integer related_task_id = 0;
		Sale response = null;
		response = service.deleteSaleTask(sale_id_1, related_task_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteSaleTask
	}

	/**
	 * Operation Unit Test
	* Delete an existing SalePig entity
	* 
	 */
	@Test
	public void deleteSaleSalePigs() {
		// TODO: JUnit - Populate test inputs for operation: deleteSaleSalePigs 
		Integer sale_id_2 = 0;
		Integer related_salepigs_id = 0;
		Sale response = null;
		response = service.deleteSaleSalePigs(sale_id_2, related_salepigs_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteSaleSalePigs
	}

	/**
	 * Operation Unit Test
	* Save an existing Sale entity
	* 
	 */
	@Test
	public void saveSale() {
		// TODO: JUnit - Populate test inputs for operation: saveSale 
		Sale sale_1 = new cn.edu.scau.cmi.hombio.domain.Sale();
		service.saveSale(sale_1);
	}

	/**
	 * Operation Unit Test
	* Save an existing SalePig entity
	* 
	 */
	@Test
	public void saveSaleSalePigs() {
		// TODO: JUnit - Populate test inputs for operation: saveSaleSalePigs 
		Integer id_3 = 0;
		SalePig related_salepigs = new cn.edu.scau.cmi.hombio.domain.SalePig();
		Sale response = null;
		response = service.saveSaleSalePigs(id_3, related_salepigs);
		// TODO: JUnit - Add assertions to test outputs of operation: saveSaleSalePigs
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
